import numpy as np
import segyio


# 将sgy数据翻转，道数据倒序排列
def reverse_sgy(file_path):
    with segyio.open(file_path, "r+", ignore_geometry=True) as segy_file:
        cdpx = np.array([t[segyio.TraceField.CDP_X] for t in segy_file.header])
        trace_num = cdpx.size
        trace_data = []
        for i in range(trace_num):
            trace_data.append(segy_file.trace[i])

        # 道数据倒序排列
        traec_data_reverse = trace_data[::-1]
        for i in range(trace_num):
            segy_file.trace[i] = traec_data_reverse[i]

if __name__ == "__main__":
    reverse_sgy(r"E:\vspData\斜井\st_reverse.sgy")
    reverse_sgy(r"E:\vspData\斜井\stkb_reverse.sgy")